package storage.buffer;

import exceptions.DBCannotUnpin;
import storage.data.Page;
import storage.data.PageID;

class Slot {
	storage.data.PageID pid ;
	int count ;
	int state ;
	boolean dirty = false ; 
	static int free = 0 ;
	static int referenced = 1 ;
	static int inUse = 2 ; 
	
	public Slot () {
		this.pid = new PageID ( Page.INVALID_PAGE.pageId ) ; 	
	}
	
	public Slot ( PageID pid ) {
		this.pid = pid ; 
	}
	
	public void pin () {
		count ++ ; 
		state = inUse ;
	}
	
	public void unpin () throws DBCannotUnpin {
		if ( count < 1 ) throw new DBCannotUnpin( null, pid ) ;
		count -- ;
		if ( count == 0) state = referenced ; 
	}
}


